//
// OpenTemplate
// Copyright (c) 2006
// by OpenArrow Software ( http://www.openarrow.com )
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 
// documentation files (the "Software"), to deal in the Software without restriction, including without limitation 
// the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and 
// to permit persons to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or substantial portions 
// of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED 
// TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF 
// CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
// DEALINGS IN THE SOFTWARE.
//

using System;
using System.Collections.Generic;
using System.Text;
using System.CodeDom.Compiler;
using OpenArrow.Templating.Properties;

namespace OpenArrow.Templating
{
    /// <summary>
    /// Represents parameters to be used by the <see cref="TemplateProcessor"/>
    /// </summary>
    public class ProcessorParameters
    {
        #region Private Fields

        private List<string> templateFileExtensions;
        private bool compileAssembly;
        private string codeDirectory;
        private CompilerParameters compilerParameters; 

        #endregion

        #region Public Properties

        /// <summary>
        /// Gets or sets an array of file extensions (including the '.') that should
        /// be considered template files.
        /// </summary>
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1002:DoNotExposeGenericLists")]
        public List<string> TemplateFileExtensions
        {
            get { return templateFileExtensions; }
        }

        /// <summary>
        /// Gets or sets a boolean indicating if an assembly should be compiled, or if the
        /// templates should just be converted to source code. (Default is true)
        /// </summary>
        public bool CompileAssembly
        {
            get { return compileAssembly; }
            set { compileAssembly = value; }
        }

        /// <summary>
        /// Gets or sets the directory that the code files will be output to
        /// </summary>
        public string CodeDirectory
        {
            get { return codeDirectory; }
            set { codeDirectory = value; }
        }

        /// <summary>
        /// Gets or sets the compiler parameters that will be used to compile the assembly if requested
        /// </summary>
        public CompilerParameters CompilerParameters
        {
            get { return compilerParameters; }
            set { compilerParameters = value; }
        } 

        #endregion

        #region Public Constructors

        /// <summary>
        /// Initializes a new instance of the ProcessorParameters class.
        /// </summary>
        /// <remarks>
        /// <list type="bullet">
        /// <item>The following extensions will be considered templates: ".ot", ".otx", ".template"</item>
        /// <item>
        /// Generated Source Code is placed in the directory specified by the <see cref="Environment.CurrentDirectory"/> property
        /// at the time of the call to this method
        /// </item>
        /// <item>An assembly will be compiled</item>
        /// <item>Default values will be assigned to all parameters in <see cref="CompilerParameters"/></item>
        /// </list>
        /// </remarks>
        public ProcessorParameters()
            : this(null, true, String.Empty, null)
        {
        }

        /// <summary>
        /// Initializes a new instance of the ProcessorParameters class.
        /// </summary>
        /// <remarks>The following extensions will be considered templates: ".ot", ".otx", ".template"</remarks>
        /// <param name="compileAssembly">A boolean indicating if an assembly should be compiled, or if source code should just be generated</param>
        /// <param name="codeDirectory">The directory in which generated source code should be placed</param>
        /// <param name="compilerParameters">Parameters to pass on to the compiler</param>
        public ProcessorParameters(bool compileAssembly, string codeDirectory, CompilerParameters compilerParameters)
            : this(null, compileAssembly, codeDirectory, compilerParameters)
        {
        }

        /// <summary>
        /// Initializes a new instance of the ProcessorParameters class.
        /// </summary>
        /// <remarks>
        /// Generated Source Code is placed in the directory specified by the <see cref="Environment.CurrentDirectory"/> property
        /// at the time of the call to this method
        /// </remarks>
        /// <param name="templateFileExtensions">The file extensions (including the '.') to treat as template files</param>
        /// <param name="compileAssembly">A boolean indicating if an assembly should be compiled, or if source code should just be generated</param>
        /// <param name="compilerParameters">Parameters to pass on to the compiler</param>
        public ProcessorParameters(List<string> templateFileExtensions, bool compileAssembly, CompilerParameters compilerParameters)
            : this(templateFileExtensions, compileAssembly, String.Empty, compilerParameters)
        {
        }

        /// <summary>
        /// Initializes a new instance of the ProcessorParameters class.
        /// </summary>
        /// <remarks>An assembly will be compiled</remarks>
        /// <param name="templateFileExtensions">The file extensions (including the '.') to treat as template files</param>
        /// <param name="codeDirectory">The directory in which generated source code should be placed</param>
        /// <param name="compilerParameters">Parameters to pass on to the compiler</param>
        public ProcessorParameters(List<string> templateFileExtensions, string codeDirectory, CompilerParameters compilerParameters)
            : this(templateFileExtensions, true, codeDirectory, compilerParameters)
        {
        }

        /// <summary>
        /// Initializes a new instance of the ProcessorParameters class.
        /// </summary>
        /// <param name="templateFileExtensions">The file extensions (including the '.') to treat as template files</param>
        /// <param name="compileAssembly">A boolean indicating if an assembly should be compiled, or if source code should just be generated</param>
        /// <param name="codeDirectory">The directory in which generated source code should be placed</param>
        /// <param name="compilerParameters">Parameters to pass on to the compiler</param>
        public ProcessorParameters(List<string> templateFileExtensions, bool compileAssembly, string codeDirectory, CompilerParameters compilerParameters)
        {
            if (templateFileExtensions == null || templateFileExtensions.Count == 0)
                templateFileExtensions = new List<string>(new string[] { ".otx", ".ot", ".template" });
            if (String.IsNullOrEmpty(codeDirectory))
                codeDirectory = Environment.CurrentDirectory;
            if (compilerParameters == null)
                compilerParameters = new CompilerParameters();

            this.templateFileExtensions = templateFileExtensions;
            this.compileAssembly = compileAssembly;
            this.codeDirectory = codeDirectory;
            this.compilerParameters = compilerParameters;
        } 

        #endregion

    }
}
